﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using FineUI;

namespace lcmyjobs.Web
{
    public partial class index : BasePage
    {
        lcmyjobs.BLL.user_adv bub = new BLL.user_adv();
        lcmyjobs.BLL.user_basic buu = new BLL.user_basic();
        lcmyjobs.BLL.links bll = new lcmyjobs.BLL.links();
        lcmyjobs.BLL.adverts ad = new BLL.adverts();
        lcmyjobs.BLL.news bn = new BLL.news();
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            //this.lbl_time.Text = System.DateTime.Now.GetDateTimeFormats('D')[3].ToString();
            if (Session["user_id"] != null)
            {
                Panel2.Visible = true;
                Panel1.Visible = false;
                Panel3.Visible = false;
                this.lblName.Text = Session["user_name"].ToString();
            }
            if (Session["enterprise_bid"] != null)
            {
                Panel3.Visible = true;
                Panel1.Visible = false;
                Panel2.Visible = false;
                this.lbl_enterprise.Text = Session["enterprise_name"].ToString();
            }
            int atid = int.Parse(Application["webid"].ToString()), count = 0;
            try
            {
                atid = int.Parse(Application["webid"].ToString());
            }
            catch (Exception ex)
            {

                //throw;
            }
            this.Title = string.Format("{1}人才网   {1}招聘网   {1}猎头网   {1}求职网   {1}人才市场  {1}人才信息   {0}", Application["webname"].ToString(), Application["webregion"].ToString());

            
            NewsList1.count = 6;
            NewsList1.typeid = 1;
            NewsList1.infourl = "../article";
            //NewsList2.count = 3;
            //NewsList2.typeid = 2;
            //NewsList2.infourl = "article.aspx";
            /*
            ds = bn.PageNews(atid, 4, 4, 2, out count);

            if (ds.Tables[0].Rows.Count > 0)
            {
                this.lti_zhaopin3.Text = "<ul class='zprc_ul zplist'>";
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    this.lti_zhaopin3.Text += " <li><a target='_blank' href='article-" + row["nid"] + ".html" + "' >" + lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28) + "</a></li> ";
                }

                this.lti_zhaopin3.Text += "</ul>";
            }

            ds = bn.GetListHotNews(atid, 4);
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.lti_zhaopin4.Text = "<ul class='zprc_ul zplist'>";

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    this.lti_zhaopin4.Text += " <li><a target='_blank' href='article-" + row["nid"] + ".html" + "' >" + lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28) + "</a></li> ";
                }
                this.lti_zhaopin4.Text += "</ul>";

            }
            ds = bn.GetTJ(atid, 4);
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.Lti_atical1.Text = "<ul class='zprc_ul zplist'>";
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    this.Lti_atical1.Text += "<li><a target='_blank' href='article-" + row["nid"].ToString() + ".html" + "' >" + lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28) + "</a>";
                }
                this.Lti_atical1.Text += "</ul>";
            }
             */ 
            /*
            if (ds.Tables[0].Rows.Count == 1)
            {
                this.lbltitle.Text = ds.Tables[0].Rows[0][1].ToString();
                this.lblcontent.Text = lcmyjobs.BLL.Tools.RemoveHtml(ds.Tables[0].Rows[0][2].ToString(), 68);
                if (lbltitle.Text.Length > 10)
                    lbltitle.Text = lbltitle.Text.Substring(0, 10);

                lblcontent.Text = lblcontent.Text + "    <a target='_blank' href='article.aspx?nid=" + ds.Tables[0].Rows[0][0].ToString() + "'>--》详细</a>";
            }
             * */

            ds = bub.PageUserAdvHunter(atid, 1, 15, out count);
            Repeater1.DataSource = ds.Tables[0];
            Repeater1.DataBind();
            ds = buu.PageUserRewardList(atid, 1, 15, out count);
            Repeater2.DataSource = ds.Tables[0];
            Repeater2.DataBind();
            ds = bll.GetList("");
            //rptlinks.DataSource = ds.Tables[0];
            //rptlinks.DataBind();
            ds = ad.GetAdvnid(0, 15);
            if (ds.Tables[0].Rows.Count > 0)
            {
                //if (ds.Tables[0].Rows.Count == 16)
                //{
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {

                        System.Web.UI.WebControls.HyperLink hl = Page.FindControl("HyperLink" + ds.Tables[0].Rows[i]["locationid"].ToString()) as System.Web.UI.WebControls.HyperLink;
                        if (hl != null)
                        {
                                hl.ImageUrl = "~" + ds.Tables[0].Rows[i][0].ToString();
                                hl.NavigateUrl = ds.Tables[0].Rows[i][1].ToString();
                                hl.Visible = true;
                        }
                    }

                //}

            }

            Bind(atid);

        }


        protected void btnout_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Panel1.Visible = true;
            Panel2.Visible = false;
            Panel3.Visible = false;
            //Response.Redirect("Default.aspx");
            Response.Redirect("index.html");
        }

        public void Bind(int atid)
        {
            //DataSet dsi = new lcmyjobs.BLL.enterprise_releasejob().GetIndexInfo(20, 20, 32, 44, atid);
            //StringBuilder str = new StringBuilder("<ul>");
         
        
           
        

            lcmyjobs.BLL.enterprise_releasejob r = new BLL.enterprise_releasejob();
            
            int cnt = 0;

            DataSet ds_Hunter = r.GetIndexInfoHunter(20, atid);
            DataSet ds_Reward = r.GetIndexInfoReward(20, atid);
            //DataSet ds_Vip = r.GetIndexInfoVip(32, atid);
            DataSet ds_Vip = r.GetIndexInfoVip(90, atid);
            DataSet ds_new = r.GetIndexInfoNew(44, atid);
            DataSet ds_frist = r.GetAllIsFristRelesJobByAtid(atid, 1, 15,out cnt);
            DataSet ds_jyzd = new lcmyjobs.BLL.news().GetListNews(Convert.ToInt32(Application["webid"].ToString()), 3, 2);
            DataSet ds_hotnews = new lcmyjobs.BLL.news().GetListHotNews(Convert.ToInt32(Application["webid"].ToString()), 3);
            DataSet ds_bottom1 = new lcmyjobs.BLL.news().GetListNews(Convert.ToInt32(Application["webid"].ToString()), 5, 3);
            DataSet ds_bottom2 = new lcmyjobs.BLL.news().GetListNews(Convert.ToInt32(Application["webid"].ToString()), 5, 4);
            DataSet ds_bottom3 = new lcmyjobs.BLL.news().GetListNews(Convert.ToInt32(Application["webid"].ToString()), 5, 8);

            #region 绑定中部新闻
            if (ds_jyzd.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder("");
                str.Append("<ul  class='zprc_ul'>");
                foreach (DataRow row in ds_jyzd.Tables[0].Rows)
                {
                    string content = lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 34);
                    str.Append("<li><a target='_blank' href='article-" + row["nid"] + ".html" + "'>" + content + "</a></li>");

                }

                str.Append("</ul>");
                this.lti_newList.Text = str.ToString();
            }

            #endregion

            #region 绑定热门文章
            if (ds_hotnews.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder("");
                str.Append("<ul  class='zprc_ul'>");
                foreach (DataRow row in ds_hotnews.Tables[0].Rows)
                {
                    string content = lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 34);
                    str.Append("<li><a target='_blank' href='article-" + row["nid"] + ".html" + "'>" + content + "</a></li>");

                }

                str.Append("</ul>");
                this.Lti_atical1.Text = str.ToString();
            }
            #endregion

            #region 绑定底部文章
            if (ds_bottom1.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder("");
                str.Append("<ul>");
                foreach (DataRow row in ds_bottom1.Tables[0].Rows)
                {
                    string content = lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28);
                    str.Append("<li><a target='_blank' href='article-" + row["nid"] + ".html" + "'>" + content + "</a></li>");

                }

                str.Append("</ul>");
                this.lti_bot1.Text = str.ToString();
            }

            if (ds_bottom2.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder("");
                str.Append("<ul>");
                foreach (DataRow row in ds_bottom2.Tables[0].Rows)
                {
                    string content = lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28);
                    str.Append("<li><a target='_blank' href='article-" + row["nid"] + ".html" + "'>" + content + "</a></li>");

                }

                str.Append("</ul>");
                this.lti_bot2.Text = str.ToString();
            }

            if (ds_bottom3.Tables[0].Rows.Count > 0)
            {
                StringBuilder str = new StringBuilder("");
                str.Append("<ul>");
                foreach (DataRow row in ds_bottom3.Tables[0].Rows)
                {
                    string content = lcmyjobs.BLL.Tools.RemoveHtml(row["ntitle"].ToString(), 28);
                    str.Append("<li><a target='_blank' href='article-" + row["nid"] + ".html" + "'>" + content + "</a></li>");

                }

                str.Append("</ul>");
                this.lti_bot3.Text = str.ToString();
            }
            #endregion

            #region 猎头职位绑定

            if (ds_Hunter.Tables[0].Rows.Count > 0)
            {
                /*
                DataRow row = ds_Hunter.Tables[0].Rows[0];

                StringBuilder str = new StringBuilder();

                str.Append(" <a target='_blank' href='../hunter/hemplistjobs.aspx?enterprise_rid= ");
                str.Append(row["enterprise_rid"]);
                str.Append("'>[");
                str.Append(row["jobs_name"]);
                str.Append("]&nbsp;");
                //str.Append("]</a>&nbsp;");
                str.Append(row["name"]);
                //str.Append("<br/>");
                str.Append("&nbsp;&nbsp;年薪");
                str.Append(row["salaryy"]);
                str.Append("万元");
                str.Append("&nbsp;&nbsp;");
                //str.Append("<br/>");
                //str.Append("<a target='_blank' href='../hunter/hemplistjobs.aspx?enterprise_rid= ");
                //str.Append(row["enterprise_rid"]);
                //str.Append("'>详情请点击...</a><br/>");
                str.Append("详情请点击...</a><br/>");
                this.ltr_hunterJobsTop.Text = str.ToString();
                if (ds_Hunter.Tables[0].Rows.Count > 8)
                {
                    StringBuilder str1 = new StringBuilder("<ul>");
                    for (int i = 1; i < 8; i++)
                    {
                        DataRow row1 = ds_Hunter.Tables[0].Rows[i];
                        SetHunterJobs(str1, row1);
                    }

                    str.Append("</ul>");
                    this.lti_hunterL.Text = str1.ToString();
                }
                else
                {
                    StringBuilder str1 = new StringBuilder("<ul>");
                    for (int i = 1; i < ds_Hunter.Tables[0].Rows.Count; i++)
                    {
                        DataRow row1 = ds_Hunter.Tables[0].Rows[i];
                        SetHunterJobs(str1, row1);
                    }

                    str.Append("</ul>");
                    this.lti_hunterL.Text = str1.ToString();
                }
                
                */
                int num = ds_Hunter.Tables[0].Rows.Count;
                if (num > 8)
                {
                    num = 8;
                }

                StringBuilder str = new StringBuilder("<ul>");
                for (int i = 0; i < num; i++)
                {
                    DataRow row = ds_Hunter.Tables[0].Rows[i];
                    SetHunterJobs(str, row);
                }

                str.Append("</ul>");
                this.lti_hunterL.Text = str.ToString();

            }



            #endregion

            #region 悬赏职位绑定
            if (ds_Reward.Tables[0].Rows.Count > 0)
            {
                int num = ds_Reward.Tables[0].Rows.Count;
                if (num > 8)
                {
                    num = 8;
                }

                StringBuilder str = new StringBuilder("<ul>");
                for (int i = 0; i < num; i++)
                {
                    DataRow row = ds_Reward.Tables[0].Rows[i];
                    SetRewardJobs(str, row);
                }
                str.Append("</ul>");
                this.lti_rewardL.Text = str.ToString();
            }


            /*
            if (ds_Reward.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds_Reward.Tables[0].Rows[0];

                StringBuilder str = new StringBuilder();

                str.Append(" <a target='_blank' href='../reward/enlistjobs.aspx?enterprise_rid= ");
                str.Append(row["enterprise_rid"]);
                str.Append("'>[");
                str.Append(row["jobs_name"]);
                str.Append("]</a>&nbsp;");
                str.Append(row["name"]);
                str.Append("<br/>");
                str.Append(GetStrSub(row["about"].ToString(), 39));
                str.Append("<br/>");
                str.Append("<a target='_blank' href='../reward/enlistjobs.aspx?enterprise_rid= ");
                str.Append(row["enterprise_rid"]);
                str.Append("'>详情请点击...</a><br/>");
                this.ltr_RewardJobsTop.Text = str.ToString();

                if (ds_Reward.Tables[0].Rows.Count > 8)
                {
                    StringBuilder str1 = new StringBuilder("<ul>");
                    for (int i = 1; i < 8; i++)
                    {
                        DataRow row1 = ds_Reward.Tables[0].Rows[i];
                        SetRewardJobs(str1, row1);
                    }

                    str.Append("</ul>");
                    this.lti_rewardL.Text = str1.ToString();


                }
                else
                {
                    StringBuilder str1 = new StringBuilder("<ul>");
                    for (int i = 1; i < ds_Reward.Tables[0].Rows.Count; i++)
                    {
                        DataRow row1 = ds_Reward.Tables[0].Rows[i];
                        SetRewardJobs(str1, row1);
                    }

                    str.Append("</ul>");
                    this.lti_rewardL.Text = str1.ToString();
                }

            }
             */



            #endregion


            #region vip职位

            if (ds_Vip.Tables[0].Rows.Count > 0)
            {
                int num = ds_Vip.Tables[0].Rows.Count;
                /*
                if (num > 60)
                {
                    num = 60;
                }
                */
                StringBuilder str1 = new StringBuilder("<ul>");
                StringBuilder str2 = new StringBuilder("<ul>");
                StringBuilder str3 = new StringBuilder("<ul>");
                for (int i = 0; i < num; i++)
                {
                    DataRow row = ds_Vip.Tables[0].Rows[i];

                    if ((i%3) == 1)
                    {
                        SetVipJobs(str1, row);
                    }
                    else if ((i % 3) == 2)
                    {
                        SetVipJobs(str2, row);
                    }
                    else
                    {
                        SetVipJobs(str3, row);
                    }

                }
                str1.Append("</ul>");
                str2.Append("</ul>");
                str3.Append("</ul>");
                this.lti_vipL.Text = str3.ToString();
                this.lti_vipM.Text = str2.ToString();
                this.lti_vipR.Text = str1.ToString();
            }

            #endregion


            #region 最新职位
            if (ds_new.Tables[0].Rows.Count > 0)
            {
                int num = ds_new.Tables[0].Rows.Count;
                if (num > 44)
                {
                    num = 44;
                }

                StringBuilder str1 = new StringBuilder("<ul>");
                StringBuilder str2 = new StringBuilder("<ul>");
                for (int i = 0; i < num; i++)
                {
                    DataRow row = ds_new.Tables[0].Rows[i];


                    if (i % 2 > 0)
                    {
                        SetNewJobs(str2, row);
                    }
                    else
                    {
                        SetNewJobs(str1, row);
                    }
                }

                str1.Append("</ul>");
                str2.Append("</ul>");
                //this.lti_newL.Text = str1.ToString();
                //this.lti_newR.Text = str2.ToString();
            }


            #endregion

            #region 急聘职位
            if(ds_frist.Tables[0].Rows.Count>0){
                rpt_jpzw.DataSource = ds_frist.Tables[0];
                rpt_jpzw.DataBind();
            }
            #endregion

        }

        private void SetVipJobs(StringBuilder str, DataRow row)
        {
            string jobsNameList = row["jobs_namelist"].ToString();
            string[] jls = jobsNameList.Split('|');
            string jobs_name = "";

            // 获取企业所发布的3个职位名称,如果不够3个职位，则获取所有职位
            if (jls.Length > 3)
            {
                for (int j = 0; j < 3; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            else
            {
                for (int j = 0; j < jls.Length; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            str.Append("<li><a target='_blank' href='../findjobs/ListVipJobs-");
            str.Append(row["enterprise_bid"]);
            str.Append(".html");
            str.Append("' onmouseover='showMessage(this,\"" + jobsNameList + "\")'>");
            str.Append("");
            str.Append(GetStrSub(row["name"].ToString(), 13));
            str.Append("");
            str.Append("</a>&nbsp;");
            str.Append(GetStrSub(jobs_name, 13));
            str.Append("<span></span></li>");
        }

        private void SetRewardJobs(StringBuilder str, DataRow row)
        {
            str.Append("<li><a target='_blank' href='../reward/enlistjobs-");
            str.Append(row["enterprise_rid"]);
            str.Append("-");
            str.Append(row["enterprise_reward_id"]);
            str.Append(".html");
            str.Append("'>");
            str.Append(GetStrSub(row["jobs_name"].ToString(), 4));
            str.Append("</a><span>悬赏金额：");
            str.Append(row["price"]);
            str.Append("元</span>");
            str.Append("<span style='width:100px;'>");
            str.Append(GetStrSub(row["area_name"].ToString(), 8));
            str.Append("</span></li>");
        }

        private void SetHunterJobs(StringBuilder str, DataRow row)
        {

            str.Append(" <li><a target='_blank' href='../hunter/hemplistjobs-");
            str.Append(row["enterprise_rid"]);
            str.Append(".html");
            str.Append("'>");
            str.Append(GetStrSub(row["jobs_name"].ToString(), 4));
            str.Append("</a>");
            str.Append("<span style='width:100px;'>");
            str.Append(GetStrSub(row["trade_name"].ToString(), 8));
            str.Append("</span>");
            //str.Append(row["name"]);
            str.Append("<span>年薪：");
            str.Append(row["salaryy"]);
            //str.Append("万元&nbsp;&nbsp;");
            str.Append("万</span><span style='width:100px;'>");
            str.Append(GetStrSub(row["area_name"].ToString(), 8));
            str.Append("</span></li>");
               

        }

        private void SetNewJobs(StringBuilder str, DataRow row)
        {
            string jobsNameList = row["jobs_namelist"].ToString();

            string[] jls = jobsNameList.Split('|');

            string jobs_name = "";

            if (jls.Length > 3)//获取企业所发布的3个职位名称,如果不够3个职位，则获取所有职位
            {
                for (int j = 0; j < 3; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            else
            {
                for (int j = 0; j < jls.Length; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            str.Append("<li><a target='_blank' href='../findjobs/JobsInfo-");
            str.Append(row["enterprise_rid"]);
            str.Append(".html");
            str.Append("' onmouseover='showMessage(this,\"" + jobsNameList + "\")'");
            str.Append("'>[");
            str.Append(GetStrSub(row["jobs_name"].ToString(), 9));
            str.Append("]</a>&nbsp;");
            str.Append(GetStrSub(row["name"].ToString(), 14));
            str.Append("<span></span></li>");
        }

        private string GetStrSub(string str, int length)
        {
            if (str.Length > length)
            {
                //return str.Substring(0, length) + "...";
                return str.Substring(0, length);
            }
            else
            {
                return str;
            }
        }

        private string GetStr(string str, int length)
        {
            string result = str;
            if (str.Length > length)
            {
                result = str.Substring(0, length);
            }
            return result;
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            // add by liuhui 如果企业登录则个人不能登录
            if (Session["enterprise_bid"] != null)
            {
                //Maticsoft.Common.MessageBox.Show(Page, "您已经登录单位账号。请先退出，才能登录个人账号！");
                Alert.Show("您已经登录单位账号。请先退出，才能登录个人账号！", MessageBoxIcon.Error);
                return;
            }
            string name = this.loginname.Text.Trim();
            string pwd = this.password.Text.Trim();
            //string checkcode = this.tbxCaptcha.Text.Trim();
            //if (Session["CheckCode"] != null)
            //{
                //if (checkcode.ToUpper() == Session["CheckCode"].ToString())
                //{
                    lcmyjobs.BLL.user_basic bad = new BLL.user_basic();
                    string mname = "";
                    string time = "";
                    pwd = myPublic.GetMd5(pwd);
                    int id = bad.UserLogin(name, pwd, out mname, out time);
                    if (id != 0)
                    {
                        Session["user_id"] = id.ToString();
                        Session["user_name"] = mname;
                        Session["user_time"] = time;
                        //Response.Redirect("user_main.html");
                        //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                        Response.Redirect("index.html");
                    }
                    else
                    {
                        //Maticsoft.Common.MessageBox.Show(this, "用户名或密码不对！");
                        Alert.Show("用户名或密码错误！", MessageBoxIcon.Error);
                    }
            /*
                }
        
                else
                {
                    //Maticsoft.Common.MessageBox.Show(this, "验证码不对！");
                    Alert.ShowInTop("验证码错误！");
                }

            }
            else
            {
                //Maticsoft.Common.MessageBox.Show(this, "验证码不对！");
                Alert.ShowInTop("验证码错误！");
            }
         */ 

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("~/index.html");
        }

        protected void lb_refresh_click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {
                int uid = int.Parse(Session["user_id"].ToString());
                int r = 0;
                r = buu.updateusertime(uid);
                if (r != 0)
                {
                    //Maticsoft.Common.MessageBox.Show(this, "刷新成功！");
                    Alert.Show("刷新成功！");
                    //lb_refresh.Enabled = false;
                }
                else
                {
                    //Maticsoft.Common.MessageBox.Show(this, "刷新失败！");
                    Alert.Show("刷新失败！");
                }

            }

        }
    }
}